//
//  TaskDetailController.swift
//  FastV
//
//  Created by DC on 2024/6/24.
//

import UIKit

class TaskDetailController: UIViewController {

<<<<<<< HEAD
    @IBOutlet weak var name1: UILabel!
    @IBOutlet weak var name2: UILabel!
    @IBOutlet weak var name3: UILabel!
    @IBOutlet weak var name4: UILabel!
    @IBOutlet weak var textView: UITextView!
    
    var task: TaskModel!
    var isRemark: Bool = false
    
    override func viewDidLoad() {
        super.viewDidLoad()
        name1.text = task.startString.showDate()
        name2.text = task.endString.showDate()
        name3.text = "\(task.progress)%"
        textView.delegate = self
        name4.text = task.level.rawValue
        if !task.remark.isBlank {
            textView.text = task.remark
        }
    }

    @IBAction func buttonClick(_ sender: UIButton) {
        let tag = sender.tag - 200
        
        switch tag {
        case 0:
            dismiss(animated: true)
            
        case 1:
            YYGTaskManager.shared.removeTask(task: task)
            DispatchQueue.main.asyncAfter(deadline: .now()+0.25, execute: DispatchWorkItem(block: {
                self.dismiss(animated: true)
                NotificationCenter.default.post(name: Notification.Name(Notice.kTaskChange), object: nil)
            }))
        case 2,3:
            textView.isUserInteractionEnabled = true
            textView.text = ""
            textView.becomeFirstResponder()
            isRemark = true
        default:
            break
        }
=======
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }


    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
>>>>>>> c1d8770387c83a01c6645dbb2f22ec7e766582c2
    }
    */

}

extension TaskDetailController: UITextViewDelegate {
    
    func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
        if text == "\n" {
          let t =  textView.text ?? ""
            if !t.isBlank {
                YYGTaskManager.shared.removeTask(task: task)
                task.remark = t
                YYGTaskManager.shared.addTask(task: task)
                MBProgressHUD.showInfo("Save Success")
            }
            return false
        }
        return true
    }
    
}
